<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Article_model extends OC_Model {

	function get_all($params = array())
	{

		$this->db->select('SQL_CALC_FOUND_ROWS *', FALSE);
		$this->db->from('articles');

		if (isset($params['sort'], $params['order']))
			$this->db->order_by($params['sort'], $params['order']);

		if (isset($params['page'], $params['rows']))
			$this->db->limit($params['rows'], (intval($params['page']-1)*intval($params['rows'])));

		if (isset($params['query']) && $params['query'] != '')
		{
			$query = $params['query'];

			$likes = array_map(
				function($f) use ($query) { return "$f LIKE '%$query%'"; },
				array(
					'a_title',
					'a_desc',
					'a_meta_keywords',
					'a_meta_descriptions',
					'a_origname'
				)
			);

			$this->db->where('('.implode(' OR ', $likes).')');
		}

		$result = $this->fetch_rows();
		return $result;
	}

	function add($data)
	{
		return $this->db->insert('articles', $data);
	}

	function edit($data, $keys)
	{
		return $this->db->update('articles', $data, $keys);
	}

	function delete($keys)
	{
		return $this->db->delete('articles', $keys);
	}

}

/* End of file page_model.php */
/* Location: .//D/noobsprojects/swanstwenty/dnetnorfintek/module_admin/articles/models/page_model.php */